$(document).ready(function() {
	initSearchData();
});

var SEARCH_NAME = 1; //租户姓名
var SEARCH_USER_NAME = 2; //租户姓名
var SEARCH_ROLE_NAME = 4; //租户姓名
function buildSearchOptions(searchType, newdata) {
	var data = [ {
		"name": "姓名",
		"type": "NAME",
		"className": "easyui-textbox",
		"id": "search_name"
	},
	{
		"name": "用户名",
		"type": "USERNAME",
		"className": "easyui-textbox",
		"id": "search_username"
	},
	{
		"name": "角色",
		"type": "ROLE_NAME",
		"className": "easyui-combobox",
		"id": "search_role_name"
	}];
	var content = "";
	var s;
	for(var i = 0; i < data.length; i++) {
		s = searchType & (1 << i);
		if(s != 0) {
			content += "<td>" + data[i].name + "</td><td><input class=\"" + data[i].className + "\" name=\"" + data[i].type + "\" id=\"" + data[i].id + "\"/></td>";
		}
	}
	if(newdata.length > 0) {
		for(var i = 0; i < newdata.length; i++) {
			content += "<td>" + newdata[i].name + "</td><td><input class=\"" + newdata[i].className + "\" name=\"" + newdata[i].type + "\" id=\"" + newdata[i].id + "\"/></td>";
		}
	}
	var contain = "<div id=\"p\" class=\"easyui-panel\" title=\"查询\" style=\"width:100%;height:100%;\"><table cellspacing=\"4\" style=\"margin-top: 10px;\"><tr>" + content;
	contain += "<td><a href=\"#\" class=\"easyui-linkbutton\" onclick=\"doSearch()\" data-options=\"iconCls:'icon-search'\" style=\"width:80px;\">查询</a></td></tr></table></div>";
	return contain;
}

function initSearchData() {
	if($("#search_role_name") != undefined) {
		$("#search_role_name").combobox({
			valueField: 'ROLE_NAME',
			textField: 'ROLE_NAME',
			mode: 'remote',
			method: 'get',
			panelHeight: 'auto',
			url: RemoteLinkAddress + '/role/listall.do',
		});
	}
}

function processSearchCondition() {
	if($("#div_search") == undefined) {
		console.log("请检查ID为div_search是否存在");
		return "";
	}
	var searchCondition = "";
	$("#div_search input[name]").each(function(index) {
		if($(this).val().trim().length != 0) {
			if(searchCondition == "") {
				searchCondition = $(this).attr("name") + "=" + $(this).val().trim();
			} else {
				searchCondition += "&" + $(this).attr("name") + "=" + $(this).val().trim();
			}
		}
	});
	return searchCondition;
}